home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ksmimecrypto.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  4.2 KB  |  129 lines

  1. /* This file is part of the KDE project
  2.  *
  3.  * Copyright (C) 2003 Stefan Rompf <sux@loplof.de>
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public License
  16.  * along with this library; see the file COPYING.LIB.  If not, write to
  17.  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19.  */
  20.  
  21. #ifndef __KSMIMECRYPTO_H
  22. #define __KSMIMECRYPTO_H
  23.  
  24.  
  25. #include <qcstring.h>
  26. #include <qptrlist.h>
  27. #include "ksslpkcs12.h"
  28. #include "ksslcertificate.h"
  29.  
  30. class KOpenSSLProxy;
  31. class KSMIMECryptoPrivate;
  32.  
  33. class KIO_EXPORT KSMIMECrypto {
  34.  public:
  35.     KSMIMECrypto();
  36.     ~KSMIMECrypto();
  37.  
  38.     enum algo { KSC_C_DES3_CBC = 1,
  39.         KSC_C_RC2_CBC_128,
  40.         KSC_C_RC2_CBC_64,
  41.         KSC_C_DES_CBC,
  42.         KSC_C_RC2_CBC_40 };
  43.  
  44.     enum rc { KSC_R_OK,        /* everything ok */
  45.           KSC_R_OTHER,     /* unspecified error */
  46.           KSC_R_NO_SSL,    /* No crypto lib / compiled without SSL */
  47.           KSC_R_NOCIPHER,  /* encryption cipher n/a */
  48.           KSC_R_NOMEM,     /* out of memory */
  49.           KSC_R_FORMAT,    /* wrong input data format */
  50.           KSC_R_WRONGKEY,  /* wrong decryption/signature key */
  51.           KSC_R_VERIFY     /* data does not match signature */
  52.     };
  53.  
  54.     /**
  55.      * Sign a message
  56.      * @param clearText MIME representation of the message (part) to sign
  57.      * @param cipherText signature to append or signature block
  58.      * @param privKey private key/certificate to sign with
  59.      * @param certs additional certificates (may be empty)
  60.      * @param detached create detached or opaque signature
  61.      * @return 0 on success
  62.      */
  63.     rc signMessage(const QCString &clearText,
  64.            QByteArray &cipherText,
  65.            const KSSLPKCS12 &privKey,
  66.            const QPtrList<KSSLCertificate> &certs,
  67.            bool detached);
  68.  
  69.     /**
  70.      * Check a detached message signature
  71.      * Will check if messages matches signature and extract certificates
  72.      * Does not check certificates for validity!
  73.      * @param clearText MIME representation of signed message (without SIG)
  74.      * @param signature signature
  75.      * @param foundCerts certificates found in this message
  76.      * @return 0 on success
  77.      */
  78.     rc checkDetachedSignature(const QCString &clearText,
  79.                   const QByteArray &signature,
  80.                   QPtrList<KSSLCertificate> &foundCerts);
  81.  
  82.     /**
  83.      * Check an opaque signed message
  84.      * Will check if signature matches and extract message
  85.      * Does not check certificates for validity!
  86.      * @param signedText signed message block
  87.      * @param clearText cleartext of signed message
  88.      * @param foundCerts certificates found in this mesasge
  89.      * @return 0 on success
  90.      */
  91.     rc checkOpaqueSignature(const QByteArray &signedText,
  92.                 QCString &clearText,
  93.                 QPtrList<KSSLCertificate> &foundCerts);
  94.     
  95.     /**
  96.      * Encrypt a message
  97.      * encrypts a message for the given list of recipients and the
  98.      * selected algorithm. Note that any algorithm <128 bytes is
  99.      * insecure and should never be used, even if SMIME-2 requires
  100.      * only RC2-40
  101.      * @param clearText MIME representation of message to encrypt
  102.      * @param cipherText returned encrypted message
  103.      * @param algorithm encryption algorithm
  104.      * @param recip recipient certificates
  105.      * @return 0 on success
  106.      */
  107.     rc encryptMessage(const QCString &clearText,
  108.               QByteArray &cipherText,
  109.               algo algorithm,
  110.               const QPtrList<KSSLCertificate> &recip);
  111.  
  112.     /**
  113.      * Decrypt a message
  114.      * @param cipherText encrypted message block
  115.      * @param clearText returns decrypted message
  116.      * @param privKey private key to use
  117.      * @return 0 on success
  118.      */
  119.     rc decryptMessage(const QByteArray &cipherText,
  120.               QCString &clearText,
  121.               const KSSLPKCS12 &privKey);
  122.  
  123.  private:
  124.     KSMIMECryptoPrivate *priv;
  125.     KOpenSSLProxy *kossl;
  126. };
  127.  
  128. #endif
  129.